package db;

import java.sql.SQLException;
import java.util.List;

@SuppressWarnings("unchecked")
public class Form {
	/**@Desc����?
	 * @param cid
	 * @throws SQLException 
	 */
	public List construtsForm(int cid) throws SQLException{
		return JdbcOperate.query("select * from " + TableConstants.ATTRIBUTE + " where cid="+cid+"order by id asc");
		
	}

	public List getForm(int cid) throws SQLException {
		return JdbcOperate.query("select * from $" + cid + "order by id asc");
	}

	public List getNewAttr(int cid) {
		return this.getAttribute(cid, "insert");
	}

	public List getUpdateAttr(int cid) {
		return this.getAttribute(cid, "update");
	}

	public List getListAttr(int cid) {
		return this.getAttribute(cid, "list");
	}

	public List getAttr(int cid) {
		return this.getAttribute(cid, null);
	}

	/**
	 * @Desc
	 * @param cid
	 * @param type�ֱ�Ϊlist��update��insert
	 */

	private List getAttribute(int cid, String type) {
		StringBuffer sb = new StringBuffer();
		List list = null;
		sb.append("select * from ");
		sb.append(TableConstants.ATTRIBUTE);
		sb.append(" t where ");
		if ("list".equals(type)) {
			sb.append("t.list_view=1 and ");
		}
		if ("update".equals(type)) {
			sb.append("t.update_view=1 and ");
		}
		if ("insert".equals(type)) {
			sb.append("t.insert_view=1 and ");
		}
		sb.append(" t.cid=");
		sb.append(cid);
		sb.append(" order by t.cid asc");
		try {
			list = JdbcOperate.query(sb.toString());
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return list;
	}
}
